package com.erp.module.xianChangPaiZhao

import android.content.Context
import com.erp.bean.AnZhuangBean
import com.erp.Interface.OnUserDataInterface
import com.erp.pull.BasePullP
import com.erp.util.JsonUtil
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject

/**
 * Created by Administrator on 2019/3/19/019.
 * 作者：刘洋
 */
class IXianChangPaiZhaoP(var list : MutableList<AnZhuangBean>, var context : Context, var V : XianChangPaiZhaoContract.XianChangPaiZhaoView):BasePullP(),XianChangPaiZhaoContract.XianChangPaiZhaoP {
    var md = XianChangPaiZhapModel()
    var sousuo = ""
    init {
        PullV=V
    }
    override fun getData(page: Int, pagesize: Int, onUserDataInterface: OnUserDataInterface) {
        md.getanzhuangphoto(context, page, pagesize, sousuo,onUserDataInterface)
    }

    override fun jsondata(data: String?) {
        if(data==null){
            return
        }
        try {
            val js = JSONArray(data)
            for (i in 0 until js.length()) {
                val anzhuang = AnZhuangBean()
                val jo = js.get(i) as JSONObject
                anzhuang.customer_name= JsonUtil.getvolue(jo,"customer_name")
                anzhuang.onum= JsonUtil.getvolue(jo,"onum")
                anzhuang.shop_name= JsonUtil.getvolue(jo,"shop_name")
                anzhuang.id= JsonUtil.getvolue(jo,"id")
                list.add(anzhuang)
            }
        } catch (e: JSONException) {
            e.printStackTrace()
        }
    }

    override fun listClean() {
        list.clear()
    }

    override fun sousuo(sousuo: String) {
        this.sousuo=sousuo
        xiala()
    }
}